package com.wc.codeforces.思维.Refined_Product_Optimality;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;

/**
 * @Author congge
 * @Date 2025/1/6 20:53
 * @description
 * https://codeforces.com/contest/2053/problem/D
 */
public class Main {
    /**
     * 思路：
     * 什么时候能够保证 P 最大呢,
     * 想一下最小的数一定会是乘数, 那一定是用最小的抵消他
     * 所以将两个列表排序, 答案就是最小
     *
     * 修改怎么处理呢, +1 会不会改变整体的排序顺序呢
     * 如果有相等的 +1, 是不是我们让最后一个 +1, 就不会改变原本的顺序了,
     * 因为最后一个相等的 c[x] < c[x + 1], x + 1可能不存在
     * 只需要比较修改前是否 c[x] < d[x] 检查是否需要 / c[x] * (c[x] + 1)
     * 修改哪一个都是同理
     */
    static FastReader sc = new FastReader();
    static PrintWriter out = new PrintWriter(System.out);
    static int N = 200010, P = 998244353;
    static int[] a = new int[N], b = new int[N], c = new int[N], d = new int[N];
    static int n, q;

    public static void main(String[] args) {
        int T = sc.nextInt();
        while (T-- > 0) {
            n = sc.nextInt();
            q = sc.nextInt();
            for (int i = 1; i <= n; i++) c[i] = a[i] = sc.nextInt();
            for (int i = 1; i <= n; i++) d[i] = b[i] = sc.nextInt();
            Arrays.sort(c, 1, n + 1);
            Arrays.sort(d, 1, n + 1);
            long res = 1;
            for (int i = 1; i <= n; i++) res = res * Math.min(c[i], d[i]) % P;
            out.print(res + " ");
            while (q-- > 0) {
                int op = sc.nextInt(), x = sc.nextInt();
                if (op == 1) {
                    int l = 1, r = n;
                    while (l < r) {
                        int mid = l + r + 1 >> 1;
                        if (c[mid] <= a[x]) l = mid;
                        else r = mid - 1;
                    }
                    if (c[l] < d[l]) res = res * qpow(a[x], P - 2) % P * (a[x] + 1) % P;
                    c[l]++;
                    a[x]++;
                } else {
                    int l = 1, r = n;
                    while (l < r) {
                        int mid = l + r + 1>> 1;
                        if (d[mid] <= b[x]) l = mid;
                        else r = mid - 1;
                    }
                    if (d[l] < c[l]) res = res * qpow(b[x], P - 2) % P * (b[x] + 1) % P;
                    d[l]++;
                    b[x]++;
                }
                out.print(res + " ");
            }
            out.println();
        }
        out.flush();
    }

    static long qpow(long a, int b) {
        long res = 1;
        while (b > 0) {
            if ((b & 1) == 1) res = res * a % P;
            a = a * a % P;
            b >>= 1;
        }
        return res;
    }
}

class FastReader {
    StringTokenizer st;
    BufferedReader br;

    FastReader() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    String nextLine() {
        String s = "";
        try {
            s = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return s;
    }

    long nextLong() {
        return Long.parseLong(next());
    }

    double nextDouble() {
        return Double.parseDouble(next());
    }

    // 是否由下一个
    boolean hasNext() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                String line = br.readLine();
                if (line == null)
                    return false;
                st = new StringTokenizer(line);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return true;
    }
}

